// index.js
// 获取应用实例
const app = getApp();
var data = require("../../utils/data");

Page({
    data: {
        //轮播图属性控制
        indicatordots: true,
        autoplay: true,
        interval: 5000,
        duration: 500,
        circular: true,
        imgUrls: data.getBinnerData,
        //导航栏
        navData: data.getIndexNavData,
        curNavId: 0,
        index: -1,
        colors: ["red", "orange", "yellow", "green", "purple"],
        //列表
        listdata: data.getListData
    },
    //点击导航栏图标
    switchNav: function(res) {
        console.log(res);
        var id = res.currentTarget.dataset.id;
        var index = res.currentTarget.dataset.index;
        this.setData({
            curNavId: id,
            index: index
        })
    },
    //加载更多
    loadMore: function(res) {
        console.log('滑倒底部');
        wx.showToast({
            title: '加载中...',
            icon: 'loading',
            duration: 5000
        })
        setTimeout(() => {
            wx.hideToast({
                success: (function(res) {
                    wx.showToast({
                        icon: 'none',
                        title: '没有更多了',
                        duration: 2000
                    })
                })
            })

        }, 1000);

    },
    //刷新
    refresh: function(res) {
        console.log("滑倒顶部，刷新界面")
        setTimeout(() => {
            wx.showToast({
                icon: 'none',
                title: "刷新成功",
                duration: 2000
            })
        }, 500);

    },
    //跳转到详情页
    navigateDetail: function(res) {
        // console.log(res)
        var imgid = res.currentTarget.id;

        wx.navigateTo({
            // url: '../detail/detail',

            url: '../detail/detail?id=' + imgid + '&index=' + this.data.index,
            success: function(res) {
                //设置详情页标题
                wx.setNavigationBarTitle({
                        title: '详情页',
                    })
                    //打开详情页时，打开加载图标
                wx.showNavigationBarLoading({

                    })
                    //设置2秒后隐藏加载图标
                setTimeout(() => {
                    wx.hideNavigationBarLoading({
                        success: (res) => {},
                    })
                }, 2000);
            }
        })
    },
    //跳转book预约页面
    navigateBook: function() {
        wx.navigateTo({

            url: '../book/book',
            success: function(res) {
                //设置预约页标题
                wx.setNavigationBarTitle({
                        title: '预约信息',
                    })
                    //     //打开详情页时，打开加载图标
                    // wx.showNavigationBarLoading({

                //     })
                //     //设置2秒后隐藏加载图标
                // setTimeout(() => {
                //     wx.hideNavigationBarLoading({
                //         success: (res) => {},
                //     })
                // }, 2000);
            }
        })
    },
    onLoad: function(options) {
        wx.showToast({
            title: '加载中',
            icon: 'loading',
            duration: 10000,
            mask: true
        })
        setTimeout(() => {
            wx.hideToast({
                success: (res) => {
                    this.setData({
                        index: 0
                    })
                    console.log("2秒后调用hidetoastAPi，调用成功后输出该行信息");
                },
            })
        }, 2000);

    }


})